package com.shop.dao;

import java.beans.Statement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.shop.dao.bean.Register;

public class LoginDSL {

	static Connection conn = null;
	static PreparedStatement pst = null;
	Statement stmt = null;
	static ResultSet rs = null;

	public LoginDSL() {
		conn = DBUtil.getConnection();
	}

	public static boolean doLogin(Register obj) {
		String Email = obj.getEmail();
		String Password = obj.getPassword();
		try {
			pst = conn
					.prepareStatement("select count(emailDb) from onlineshopping.member where emailDB=? and password=?");
			pst.setString(1, Email);
			pst.setString(2, Password);
			rs = pst.executeQuery();
			while (rs.next()) {
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;

	}

	public boolean doRegister(Register obj) throws SQLException {
		boolean flag = false;
		pst = (PreparedStatement) conn
				.prepareStatement("INSERT INTO onlineshopping.member (FName,LName,Address,Country,State,City,Mobile,Email,Password) VALUES(?,?,?,?,?,?,?,?,?)");

		int count = 0;
		pst.setString(1, obj.getFName());
		pst.setString(2, obj.getLName());
		pst.setString(3, obj.getAddress());
		pst.setString(4, obj.getCountry());
		pst.setString(5, obj.getState());
		pst.setString(6, obj.getCity());
		pst.setInt(7, obj.getMobile());
		pst.setString(8, obj.getEmail());
		pst.setString(9, obj.getPassword());
		count = pst.executeUpdate();
		if (count > 0) {
			flag = true;
			return flag;
		}
		pst.close();
		return flag;

	}

}
